<div id="app">
  <div class="p2 flex">
    <a href="javascript:history.go(-1)" class="weui-btn weui-btn_mini weui-btn_default"> 返回 </a>
    <div style="flex: 1"></div>
    <div class="weui-btn weui-btn_mini weui-btn_warn" @click="clearAll">清空所有</div>
  </div>

  <div class="m1">
    <div class="weui-cells">
      <div class="weui-cell">
        <div class="weui-cell__bd">
          <input class="weui-input" v-model="search" placeholder="输入名字搜索用户" />
        </div>
      </div>
    </div>
  </div>
  <div>
    <div class="weui-cells__title">用户积分</div>
    <div class="weui-cells">
      <a v-if="!search || (user.userinfo && user.userinfo.nickname.indexOf(search)>=0) "
        v-bind:href="'/client/user/'+user.contactid" class="weui-cell weui-cell_access" v-for="user in users">
        <div class="weui-cell__hd">
          <!-- <img
            style="width: 40px; height: 40px"
            class="circle"
            v-bind:src="user.userinfo?user.userinfo.headimgurl:'/img/user.png'"
          /> -->
        </div>
        <div class="weui-cell__bd px1">{{user.userinfo?user.userinfo.nickname:user.contactid}}</div>
        <div class="weui-cell__ft">{{user.point}}</div>
      </a>
    </div>

    <div v-if="users.length==0" class="gray my2 center">
      <img src="/img/empty.png" style="width: 150px" />
      <div class="font-12 bold">没有更多数据了</div>
    </div>
  </div>
  <!-- <div class="p2 font-12 gray center">到底了~</div> -->
</div>

<script>
  new Vue({
    el: "#app",
    data: {
      clientid: "<%=client._id%>",
      users: [],
      search: "",
    },

    created: function () {
      this.refresh();
    },
    methods: {
      refresh: function () {
        let that = this;
        let loading = weui.loading();
        axios.get("/client/getUsers").then(function (res) {
          let { users } = res.data;
          loading.hide();
          console.log(users);
          that.users = users;
        });
      },
      clearAll: function () {
        let that = this;
        weui.confirm(
          "同时删除所有用户积分记录, 并且无法恢复.",
          function () {
            axios.post(
              "/client/clear/points",
              {
                clientid: that.clientid,
              },
              function (res) {
                weui.toast("清空成功");
                location.refresh();
              }
            );
          },
          function () { },
          { title: "清空所有群积分" }
        );
      },
    },
  });
</script>